/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */

import { RoleType, UserType } from "@/types/user";
import request from "@/utils/request";

// 登录
export const userLogin = (user: UserType) => {
  return request.post("login", user);
};

// 注册管理员
export const userReg = (user: UserType) => {
  return request.post("users", user);
};

// 新增角色
export const rolePost = (role: RoleType) => {
  return request.post("classes/ReactRole", role);
};

// 加载角色
export const roleGet = (roleId?: string) => {
  let id = roleId ? `/${roleId}` : "";
  return request.get(`classes/ReactRole${id}`);
};

// 更新角色
export const rolePut = (roleId: string, role: RoleType) => {
  return request.put(`classes/ReactRole/${roleId}`, role);
};

// 删除角色
export const roleDel = (roleId: string) => {
  return request.delete(`classes/ReactRole/${roleId}`);
};

// 批量删除角色
export const roleBatchDel = (roles: RoleType[]) => {
  let requests = roles.map((item) => {
    return {
      method: "DELETE",
      path: `/1.1/classes/ReactRole/${item.objectId}`,
    };
  });
  return request.post(`batch`, { requests });
};

//报名列表
export const joinGet = () => {
  return request.get("classes/ReactJoin");
};

//查询报名用户信息
export const userGet = (userId: string) => {
  return request.get(`users/${userId}`);
};

export const joinUpdate = (objectId: string, status: number) => {
  return request.put(`classes/ReactJoin/${objectId}`, { status });
};
